package com.xwdeshj.controller;

import com.alibaba.fastjson.JSON;
import com.xwdeshj.servcie.MailServcie;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.junit4.SpringRunner;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by BKWJA on 2019/3/19.
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class MailServcieController {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private MailServcie mailservcie;

    @Resource
    private TemplateEngine templateEngine;

    @Test
    public void sendEmil(){

        try {
            Map<String,Object> hashMap = new HashMap<String,Object>();
            hashMap.put("Legal","张会");
            hashMap.put("time",dateFormat.format(new Date()));
            hashMap.put("name","hyr");
            hashMap.put("stauts","通过");
            Context context = new Context();
            context.setVariables(hashMap);

            String emailContext = templateEngine.process("MailBusinessTemple",context);
           JSON reult =  mailservcie.sendHTMLEmil("862526226@qq.com","用户升级为商家审核通知",emailContext);

           System.out.println(reult.toString());

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
